package top.infopub.mgr.mkt.web;

import com.github.pagehelper.Page;
import com.sun.mail.imap.protocol.ID;
import org.apache.commons.lang.StringUtils;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.mgr.flow.web.GenericFlowController;
import top.infopub.mgr.mkt.domain.ProjectDomain;
import top.infopub.mgr.mkt.service.CollectProjectService;
import top.infopub.mgr.mkt.service.MarketManageService;
import top.infopub.mgr.mkt.service.MarketingProjectService;
import top.infopub.mgr.mkt.vo.MarketingVo;
import top.infopub.mgr.util.DateUtils;
import top.infopub.model.hr.OrgInfo;
import top.infopub.model.hr.StaffInfo;
import top.infopub.model.mkt.CollectProject;
import top.infopub.security.util.SessionUserUtils;
import top.infopub.security.vo.AuthorizationVO;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 市场管理
 */
@Controller
@RequestMapping("/marketManage")
public class MarketManageController  extends GenericFlowController {

    @Autowired
    MarketingProjectService marketingProjectService;

    @Autowired
    private MarketManageService marketManageService;

    @Autowired
    private CollectProjectService collectProjectService;

    /**
     * 营销立项列表
     * @return
     */
    @RequestMapping("/mktProList")
    public String mktProList(HttpServletRequest request) {
        //获取登录人员信息
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        //查询区域公司列表
        List<OrgInfo> orgInfoList = marketManageService.queryOrgInfoByAuthUserId(vo);
        request.setAttribute("orgInfoList", orgInfoList);
        //查询营销人员列表
        List<StaffInfo> staffInfoList = marketManageService.queryStaffInfoByAuthUserId(vo);
        request.setAttribute("staffInfoList", staffInfoList);
        return "mkt/lay-marketingProject-list";
    }

    @RequestMapping(value = "/queryDataByCondition",method = RequestMethod.GET)
    @ResponseBody   //MarketingVo marketingVo,
    public RspVo<ProjectDomain> queryDataByCondition(
            ParamPage paramPage, String proName, String hrOrgId, String date, String proStage) {
       // String object = StringEscapeUtils.unescapeJava(page);
        MarketingVo marketingVo = new MarketingVo();
        marketingVo.setProName(proName);
        marketingVo.setHrOrgId(hrOrgId);
        if (StringUtils.isNotBlank(date)) {
            marketingVo.setDate(DateUtils.parseDateByFormat(date, "yyyy-MM-dd"));
        }
        marketingVo.setProStage(proStage);
        Page<ProjectDomain> page = new Page<ProjectDomain>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        page = marketingProjectService.selectPage(page, marketingVo);
        return RspVo.getSuccessResponse(page.getTotal(), page.getResult());
    }


    /**
     * 投标管理列表
     * @return
     */
    @RequestMapping("/bidManageList")
    public String bidManageList(HttpServletRequest request) {
        //获取登录人员信息
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        //查询区域公司列表
        List<OrgInfo> orgInfoList = marketManageService.queryOrgInfoByAuthUserId(vo);
        request.setAttribute("orgInfoList", orgInfoList);
        //查询营销人员列表
        List<StaffInfo> staffInfoList = marketManageService.queryStaffInfoByAuthUserId(vo);
        request.setAttribute("staffInfoList", staffInfoList);
        return "mkt/lay-bidManage-list";
    }
}
